﻿
using PoemGame.PoemDataXml;
using PoemGame.Domain.GameAggregate;
using PoemGame.Domain.PlayerAggregate;
using PoemGame.Domain.Services.Factory.Simple;
using PoemGame.Repository.Simple;

var game = new Game(Guid.NewGuid(), new GameType("Feihualing",""),PlayType.Inturn,"新游戏", "花");
var factory = new CheckAnswerServiceFactory(new PoemServiceXml());
var playerRep = new PlayerRepository();

var player1 = new Player(Guid.NewGuid(), "张三","三郎",100 );
var player2 = new Player(Guid.NewGuid(), "李四", "四郎", 100);
var player3 = new Player(Guid.NewGuid(), "王五", "五郎", 100);
await playerRep.AddAsync(player1);
await playerRep.AddAsync(player2);
await playerRep.AddAsync(player3);

game.PlayerJoinGame(player1);
game.PlayerJoinGame(player2);
game.PlayerJoinGame(player3);
game.SetPlayerInturn(player1.Id);
var note = "请输入一句唐诗，带“花”";
Console.WriteLine(note);
do
{
    Console.WriteLine("当前用户:"+game.GetCurrentPlayer().UserName);
    var answer = Console.ReadLine();
    var cup = await playerRep.GetPlayerByUserNameAsync(game.GetCurrentPlayer().UserName);
    var res = await game.Play(cup,answer,factory);
    if (res)
    {
        Console.WriteLine(cup.UserName + "回答正确");
        var u = game.GetNextPlayer(cup.Id);
        if(u!=null)
            game.SetPlayerInturn(u.PlayerId);
        else
        {
            game.GameOver(cup);
            Console.WriteLine("赢家:" + cup.UserName);
        }
            
    }
    else
    {
        game.SetPlayerOut(cup.Id);
        Console.WriteLine(cup.UserName + "出局");
    }
   // Console.WriteLine(res.Message);
} while (game.Status != GameStatus.Done);
//Console.WriteLine("赢家:" + game.);
Console.WriteLine("游戏结束");
